package com.ts.content.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ts.common.core.utils.Result;
import com.ts.common.security.dto.UserLoginDto;
import com.ts.content.entity.CategoryEntity;
import com.ts.content.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 类目
 *
 * @author admin admin@qq.com
 * @since 1.0.0 2023-02-22
 */
@RestController
@RequestMapping("/category")
@Api(tags="类目")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 以下是提供远程调用的
     */
    /** 分页查询类目表中的数据 */
    @PostMapping("/page")
    @ApiOperation("分页")
    public Page<CategoryEntity> page(@RequestBody Page<CategoryEntity> page){
        return categoryService.page(page);
    }

    /** 添加类目的接口*/
    @PostMapping("/save")
    @ApiOperation("添加")
    public Result save(@RequestBody CategoryEntity categoryEntity){
        categoryService.save(categoryEntity);
        return new Result();
    }
    /** 以上是提供远程调用的*/

    @GetMapping("/classList")
    public Result classList(UserLoginDto userLoginDto){
        log.debug("userLoginDto:{}",userLoginDto);
        List<CategoryEntity> list = categoryService.list();
        return new Result().Viewok(list);
    }

}